<#macro content>
<article class="cl pd-20">
    <form action="/core/role/<#if role??>update<#else>save</#if>" method="post" class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="id" value="${(role.id)!}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
            <div class="formControls col-xs-7 col-sm-8">
                <input type="text" class="input-text" value="${(role.name)!}" placeholder="请输入角色名称" id="name" name="name">
            </div>
            <label class="form-label col-xs-1 col-sm-1"></label>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>角色描述：</label>
            <div class="formControls col-xs-7 col-sm-8">
                <textarea name="desc" cols="" rows="" class="textarea"  placeholder="请输入角色描述">${(role.desc)!}</textarea>
            </div>
            <label class="form-label col-xs-1 col-sm-1"></label>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色权限：</label>
            <div class="formControls col-xs-7 col-sm-8">
                <#if curUserHasRolePermList?? && curUserHasRolePermList?size gt 0>
                <#list curUserHasRolePermList as f>
                <dl class="permission-list">
                    <dt>
                        <label>
                            <input type="checkbox" value="${(f.permission)!}" name="permissions" id="btn-${f_index}"> ${(f.name)!}
                        </label>
                    </dt>
                    <dd>
                        <#if f.children?? && f.children?size gt 0>
                        <#list f.children as m>
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" value="${(m.permission)!}" name="permissions" id="btn-${f_index}-${m_index}"> ${(m.name)!}
                                </label>
                            </dt>
                            <dd>
                                <#if m.children?? && m.children?size gt 0>
                                <#list m.children as b>
                                <label class="">
                                    <input type="checkbox" value="${(b.permission)!}" name="permissions" id="btn-${f_index}-${m_index}-${b_index}" <#if waitAuthRolePermList?? && waitAuthRolePermList?seq_contains('${(b.permission)!}')>checked</#if>> ${(b.name)!}
                                </label>
                                </#list>
                                </#if>
                            </dd>
                        </dl>
                        </#list>
                        </#if>
                    </dd>
                </dl>
                </#list>
                </#if>
            </div>
            <label class="form-label col-xs-1 col-sm-1"></label>
        </div>

        <div class="row cl">
            <div class="col-xs-7 col-sm-8 col-xs-offset-4 col-sm-offset-3">
                <button class="btn btn-primary radius form-submit" type="button">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
            </div>
        </div>

    </form>
</article>
</#macro>

<#assign css>
<link rel="stylesheet" type="text/css" href="/lib/fselect/fselect.css" />
</#assign>
<#assign js>
<script type="text/javascript" src="/lib/fselect/fselect.js"></script>
<script type="text/javascript">
$(function(){
    $(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dt input:checkbox").click(function(){
		$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	$(".permission-list2 dd input[type=checkbox]:checked").each(function(){
        $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
        $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
	});
})
</script>
</#assign>
<#include "../../common/layout.html"/>